# type用法一  返回变量的类型
# class Person:
#     pass
#
#
# p1 = Person()
# print(type(p1))
# print(type(Person))
#
# a = int(10)
# print(type(a))
# print(type(int))

#
# # type用法二  创建类
# # print(type(type))
# class A:
#     pass
# class C:
#     pass
# class B(C):
#     pass
#
# @staticmethod
# def say_hello():
#     print("hello")
# # 第一参数是类名  第二个参数是父类 元组  第三个参数
# ABCD = type("Person", (A, B), {
#     "__doc__": """
#     我是使用type来创建出来的类
#     """,
#     "say_hello": say_hello
# })
# # print(ABCD.__name__, type(ABCD), callable(ABCD))
# print(ABCD.__bases__, ABCD.mro())
# print(ABCD.__doc__)
# ABCD.say_hello()
# abcd = ABCD()
# print(abcd, type(abcd))


# 通过metaclass 来指定 使用type类来创建Person
# 修改通过metaclass 来指定使用MyType来来创建Person


# class MyType(type):
#     def __new__(cls, *args, **kwargs):
#         print(args, kwargs)
#         new_dict = {}
#         for k, v in args[2].items():
#             if not k.startswith("__"):
#                 new_k = ""
#                 for i in range(len(k)):
#                     if k[i].isupper():
#                         if i != 0:
#                             new_k += "_"
#                         new_k += k[i].lower()
#                     else:
#                         new_k += k[i]
#                 new_dict[new_k] = v
#             else:
#                 new_dict[k] = v
#         new_args = (args[0], args[1], new_dict)
#
#         return super().__new__(cls, *new_args, **kwargs)
#
#
# # SayHello   say_hello
# class Person(metaclass=MyType):
#     # class Person(metaclass=type):
#     def SayHello(self):
#         """
#         定义不符合函数名约定  会通过元类改写为 say_hello
#         """
#         print("hello")
#     def HI(self):
#         print("hi")
#
# p1 = Person()
# p1.say_hello()
# p1.h_i()



# class ABC:
#     pass
#
# def to_class(f):
#     def convert():
#         print(f.__name__)
#         MYCLASS = type(f.__name__.replace("_", "").title(), (ABC, ), {"__doc__": "我是新创建的类"})
#         return  MYCLASS
#     return convert
#
# @to_class
# def my_fun():
#     pass
#
#
# r = my_fun()
# print(r.__name__, r.__bases__, r.__doc__)
# abc = r()
# print(abc, type(abc))












